import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ListDemo {

	public static void main(String[] args) {

		// Here we construct our list using LinkedList implementation
		ArrayList<String> list = new ArrayList<String>();
		// However we can use any class which implements List interface

		// We can add items
		list.add("Zagorka");
		list.add("Ariana");
		list.add("Shumensko");
		list.add("Kamenitza");

		// We can check if item exists in our list
		System.out.println(list.contains("Kamenitza")); // true
		System.out.println(list.contains("Guinnes")); // false
		
		// We can retrieve the list size
		System.out.println(list.size());
		
		// We can retrieve element at index
		System.out.println(list.get(2));
		
		// We can remove an item
		list.remove("Ariana");

		// We can get item's index and set it with a new value
		list.set(list.indexOf("Zagorka"), "Pirinsko");

		// We can iterate it with the new foreach loop
		for (String s : list) {
			System.out.println(s);
		}

		// The upper is equivelent to this
		Iterator<String> iterator = list.iterator();
		while (iterator.hasNext()) {
			System.out.println(iterator.next());
		}
		
		list.subList(0, 1).clear();
		System.out.println(list);
	}

}
